package com.schoolcloud.serve.controller;

import com.schoolcloud.common.model.PageDTO;
import com.schoolcloud.common.model.R;
import com.schoolcloud.common.util.UserContext;
import com.schoolcloud.serve.entity.LostItems;
import com.schoolcloud.serve.query.LostItemQuery;
import com.schoolcloud.serve.service.LostItemsService;
import com.schoolcloud.serve.vo.LostFoundInfoVO;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

import java.time.LocalDateTime;

@RestController
@RequestMapping("/serve/lostItems")
@RequiredArgsConstructor
public class LostItemsController {
    private final LostItemsService lostItemsService;

    @GetMapping("/page")
    public R<PageDTO<LostItems>> getLostItemsPage(LostItemQuery query) {
        PageDTO<LostItems> pageDTO = lostItemsService.getLostItemsPage(query);
        return R.ok(pageDTO);
    }

    @PostMapping
    public R<?> save(@RequestBody LostFoundInfoVO lostItems) {
        lostItems.setUserId(UserContext.getUserToInteger());
        lostItemsService.saveLostItems(lostItems);
        return R.ok().setMsg("添加成功");
    }

    @PutMapping
    public R<?> update(@RequestBody LostFoundInfoVO lostItems) {
        lostItemsService.saveLostItems(lostItems);
        return R.ok().setMsg("修改成功");
    }

    @GetMapping("/{id}")
    public R<LostFoundInfoVO> getById(@PathVariable Integer id) {
        LostFoundInfoVO lostItems = lostItemsService.getLostInfo(id);
        return R.ok(lostItems);
    }
    @DeleteMapping("/{id}")
    public R delete(@PathVariable Integer id) {
        lostItemsService.removeById(id);
        return R.ok();
    }
}
